/**
 * 
 */
package com.indux.prefset.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.indux.prefset.db.constants.TblCol;

/**
 * @author IndUX
 *
 */
public class DBOprHelper extends SQLiteOpenHelper
{
	
	public DBOprHelper(Context context)
	{
		super(context, DBManager.DATABASE_NAME, null,
		        DBManager.DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		StringBuilder sb = new StringBuilder();
		sb.append("CREATE TABLE ").append(DBManager.USER_DATA_TABLE_NAME)
		        .append(" (").append("_id INTEGER PRIMARY KEY AUTOINCREMENT,")
		        .append(TblCol.COL_TYPE.getFieldName() + " TEXT,")
		        .append(TblCol.COL_NAME.getFieldName() + " TEXT,")
		        .append(TblCol.COL_PARAM_NAME.getFieldName() + " TEXT,")
		        .append(TblCol.COL_PARAM_VALUE.getFieldName() + " TEXT")
		        .append(");");
		
		db.execSQL(sb.toString());
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		db.execSQL("drop table if exists " + DBManager.USER_DATA_TABLE_NAME
		        + "; ");
		onCreate(db);
	}
	
	@Override
	public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		db.execSQL("drop table if exists " + DBManager.USER_DATA_TABLE_NAME
		        + "; ");
		onCreate(db);
	}
	
}
